<?php

namespace App\Admin\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * @todo: Refactor this class by using something like MenuBuilder Helper.
 */
class City extends Model
{
    protected $table = 'ims_xzbb_city';

    protected $guarded = [];

    protected $primaryKey = 'id';

    public static function getAll()
    {
        $result = City::get();
        $result = json_decode(json_encode($result), true);
        return $result;
    }

    public static function getProvince()
    {
        $result = City::distinct()->select(['address'])->get();
        $result = json_decode(json_encode($result), true);
        return $result;
    }

    public static function getByProvince($province)
    {
        $result = City::where('address', $province)->get();
        $result = json_decode(json_encode($result), true);
        return $result;
    }

    public static function getProvinceByCity($id)
    {
        $result = City::find($id);
        if (!empty($result)) {
            return $result['address'];
        } else {
            return null;
        }
    }
}
